home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.3)
-
- import urllib
- import urllib2
- import urlparse
- import sys
- import os
- import re
- import string
- import plistlib
- import download
- from threading import Event
- from time import *
- import feedparser
- import typeFile
- VERSION = '2.2.6'
- USER_AGENT = 'iPodderX/' + VERSION + ' (http://iPodderX.com)'
- LITE = 0
-
- class iPXURLOpener(urllib.FancyURLopener):
-
- def __init__(self, *args):
- self.version = USER_AGENT
- urllib.FancyURLopener.__init__(self, *args)
-
-
- urllib._urlopener = iPXURLOpener()
- urllib._urlopener.addheader('Referer: http://iPodderX.com')
- userPath = os.path.expanduser('~')
- logFile = userPath + '/Library/Logs/iPodderX.log'
- rssPath = userPath + '/Library/Application Support/iPodderX/'
- downloadDirectory = '~/Desktop/iPodderX Downloads/'
- onlyAudio = 0
- moveAudio = 1
- deleteAudio = 0
- moveImages = 1
- deleteImages = 0
- torrentFiles = 1
- organizeDownloads = 1
- feedDetails = []
- totalBTFileSize = 0.0
- DEBUG = 0
- timeBombFile = userPath + '/Library/Application Support/.ipx.frf.plist'
- pList = userPath + '/Library/Preferences/com.thunderstonemedia.iPodderX.plist'
-
- try:
- Prefs = plistlib.Plist.fromFile(file(pList))
- except:
- Prefs = plistlib.Plist()
-
- feedFile = rssPath + 'feeds.plist'
-
- try:
- FeedListPrefs = plistlib.Plist.fromFile(file(feedFile))
- except:
- FeedListPrefs = plistlib.Plist()
-
- historyFile = rssPath + 'history.plist'
- historyURLs = []
- encGUIDs = []
- History = plistlib.Plist()
-
- def trimLog():
-
- try:
- f = open(logFile, 'r')
- data = os.popen('tail -500 ' + logFile).readlines()
- f.close()
- f = open(logFile, 'w')
- for line in data:
- f.write(line)
-
- f.close()
- except:
- pass
-
-
-
- def logIt(msg):
- if DEBUG:
- print msg
- sys.stdout.flush()
-
- if os.path.isfile(logFile):
- f = open(logFile, 'a')
- f.write(msg + '\r\n')
- f.close()
- elif os.path.isdir(userPath + '/Library/Logs'):
- f = open(logFile, 'w')
- f.write(msg + '\r\n')
- f.close()
- else:
- os.mkdir(userPath + '/Library/Logs')
- f = open(logFile, 'w')
- f.write(msg + '\r\n')
- f.close()
-
-
- def latin1_to_ascii(unicrap):
- '''This takes a UNICODE string and replaces Latin-1 characters with
- something equivalent in 7-bit ASCII. It returns a plain ASCII string.
- This function makes a best effort to convert Latin-1 characters into
- ASCII equivalents. It does not just strip out the Latin-1 characters.
- All characters in the standard 7-bit ASCII range are preserved.
- In the 8th bit range all the Latin-1 accented letters are converted
- to unaccented equivalents. Most symbol characters are converted to
- something meaningful. Anything not converted is deleted.
- '''
- xlate = {
- 192: 'A',
- 193: 'A',
- 194: 'A',
- 195: 'A',
- 196: 'A',
- 197: 'A',
- 198: 'Ae',
- 199: 'C',
- 200: 'E',
- 201: 'E',
- 202: 'E',
- 203: 'E',
- 204: 'I',
- 205: 'I',
- 206: 'I',
- 207: 'I',
- 208: 'Th',
- 209: 'N',
- 210: 'O',
- 211: 'O',
- 212: 'O',
- 213: 'O',
- 214: 'O',
- 216: 'O',
- 217: 'U',
- 218: 'U',
- 219: 'U',
- 220: 'U',
- 221: 'Y',
- 222: 'th',
- 223: 'ss',
- 224: 'a',
- 225: 'a',
- 226: 'a',
- 227: 'a',
- 228: 'a',
- 229: 'a',
- 230: 'ae',
- 231: 'c',
- 232: 'e',
- 233: 'e',
- 234: 'e',
- 235: 'e',
- 236: 'i',
- 237: 'i',
- 238: 'i',
- 239: 'i',
- 240: 'th',
- 241: 'n',
- 242: 'o',
- 243: 'o',
- 244: 'o',
- 245: 'o',
- 246: 'o',
- 248: 'o',
- 249: 'u',
- 250: 'u',
- 251: 'u',
- 252: 'u',
- 253: 'y',
- 254: 'th',
- 255: 'y',
- 161: '!',
- 162: '{cent}',
- 163: '{pound}',
- 164: '{currency}',
- 165: '{yen}',
- 166: '|',
- 167: '{section}',
- 168: '{umlaut}',
- 169: '{C}',
- 170: '{^a}',
- 171: '<<',
- 172: '{not}',
- 173: '-',
- 174: '{R}',
- 175: '_',
- 176: '{degrees}',
- 177: '{+/-}',
- 178: '{^2}',
- 179: '{^3}',
- 180: "'",
- 181: '{micro}',
- 182: '{paragraph}',
- 183: '*',
- 184: '{cedilla}',
- 185: '{^1}',
- 186: '{^o}',
- 187: '>>',
- 188: '{1/4}',
- 189: '{1/2}',
- 190: '{3/4}',
- 191: '?',
- 215: '*',
- 247: '/' }
- r = ''
- for i in unicrap:
- if xlate.has_key(ord(i)):
- r += xlate[ord(i)]
- continue
- if ord(i) >= 128:
- continue
- r += str(i)
-
- return r
-
-
- def updatePlaylist(saveLocation, saveName, playList, customGenre):
- print 'Updating iTunes...'
- sys.stdout.flush()
- location = ''
- trackID = 0
- fullPath = saveLocation + '/' + saveName
- song = os.path.abspath(fullPath)
- f = open('/tmp/iPodder-iTunes.applescript', 'w')
- f.write('set theTrackID to 0' + '\r\n')
- f.write('tell application "System Events"' + '\r\n')
- f.write('if exists process "iTunes" then' + '\r\n')
- f.write('tell application "iTunes"' + '\r\n')
- f.write('if (not (exists user playlist "' + playList + '")) then make new playlist with properties {name:"' + playList + '"}' + '\r\n')
- f.write('try' + '\r\n')
- f.write('set theTrack to add POSIX file "' + song + '" to playlist "Library" of source "Library"' + '\r\n')
- f.write('set theTrackID to the database ID of theTrack' + '\r\n')
- f.write('try' + '\r\n')
- f.write('duplicate theTrack to the playlist "' + playList + '"' + '\r\n')
- f.write('end try' + '\r\n')
- if len(customGenre) > 0:
- f.write('set theLibraryID to the index of the container of (the container of theTrack)' + '\r\n')
- f.write('set genre of (some track of library playlist theLibraryID whose database ID is theTrackID) to "' + customGenre + '"' + '\r\n')
-
- f.write('on error theMessage' + '\r\n')
- f.write('log "Error:" & theMessage' + '\r\n')
- f.write('end try' + '\r\n')
- f.write('end tell' + '\r\n')
- f.write('else' + '\r\n')
- f.write('tell application "iTunes"' + '\r\n')
- f.write('set visible of front window to false' + '\r\n')
- f.write('if (not (exists user playlist "' + playList + '")) then make new playlist with properties {name:"' + playList + '"}' + '\r\n')
- f.write('try' + '\r\n')
- f.write('set theTrack to add POSIX file "' + song + '" to playlist "Library" of source "Library"' + '\r\n')
- f.write('set theTrackID to the database ID of theTrack' + '\r\n')
- f.write('try' + '\r\n')
- f.write('duplicate theTrack to the playlist "' + playList + '"' + '\r\n')
- f.write('end try' + '\r\n')
- if len(customGenre) > 0:
- f.write('set theLibraryID to the index of the container of (the container of theTrack)' + '\r\n')
- f.write('set genre of (some track of library playlist theLibraryID whose database ID is theTrackID) to "' + customGenre + '"' + '\r\n')
-
- f.write('on error theMessage' + '\r\n')
- f.write('log "Error:" & theMessage' + '\r\n')
- f.write('end try' + '\r\n')
- f.write('end tell' + '\r\n')
- f.write('end if' + '\r\n')
- f.write('end tell' + '\r\n')
- f.write('return theTrackID')
- f.close()
- ret_pipe = os.popen('/usr/bin/osascript /tmp/iPodder-iTunes.applescript')
-
- try:
- trackID = int(ret_pipe.readline())
- except:
- pass
-
- logIt('TrackID for iTunes is: ' + str(trackID))
- if trackID > 0:
- location = 'iTunes'
- if deleteAudio > 0:
- print 'Deleting: ' + fullPath + '...'
- sys.stdout.flush()
-
- try:
- os.unlink(fullPath)
-
-
- else:
- print 'iTunes failed to update. Track left in iPodderX Library'
- logIt('iTunes failed to update. Track left in iPodderX Library')
- logIt('iTunes TrackID error:')
- for line in ret_pipe.readlines():
- logIt(line)
-
- sys.stdout.flush()
- if not DEBUG:
- os.unlink('/tmp/iPodder-iTunes.applescript')
-
- return (trackID, location)
-
-
- def updateiPhoto(saveLocation, saveName, photoAlbum):
- print 'Updating iPhoto...'
- sys.stdout.flush()
- location = ''
- iPhotoID = '0'
- fullPath = saveLocation + '/' + saveName
- f = open('/tmp/iPodder-iPhoto.applescript', 'w')
- f.write('set thePhotoID to "A"' + '\r\n')
- f.write('tell application "iPhoto"' + '\r\n')
- f.write('if not (exists album "' + photoAlbum + '") then' + '\r\n')
- f.write('new album name "' + photoAlbum + '"' + '\r\n')
- f.write('end if' + '\r\n')
- f.write('set thePhoto to "' + fullPath + '"' + '\r\n')
- f.write('import from thePhoto to album "' + photoAlbum + '"' + '\r\n')
- f.write('end tell' + '\r\n')
- f.write('return thePhotoID' + '\r\n')
- f.close()
- ret_pipe = os.popen('/usr/bin/osascript /tmp/iPodder-iPhoto.applescript')
- iPhotoID = ret_pipe.readline()
- if iPhotoID == 'A':
- location = 'iPhoto'
- if deleteImages > 0:
- print 'Deleting: ' + fullPath + '...'
- sys.stdout.flush()
-
- try:
- os.unlink(fullPath)
-
-
- else:
- print 'iPhoto failed to update. Image left in iPodderX Library'
- sys.stdout.flush()
- os.unlink('/tmp/iPodder-iPhoto.applescript')
- return (iPhotoID, location)
-
-
- def initialize():
- print 'Checking ' + downloadDirectory + '...'
- sys.stdout.flush()
- checkDir(downloadDirectory)
- print 'Checking ' + rssPath + '...'
- sys.stdout.flush()
- checkDir(rssPath)
-
-
- def downloadDir():
- defaultDir = '~/Desktop/iPodderX'
-
- try:
- d = Prefs['downloadDirectory']
- except:
- d = defaultDir
-
- if d == '':
- d = defaultDir
-
- d = d.replace('~', userPath)
- if d[len(d) - 1:len(d)] != '/':
- d += '/'
-
- return d
-
-
- def checkReg():
- if LITE:
- return 1
-
- if os.path.isfile(timeBombFile):
- return 1
- else:
-
- try:
- regCode = Prefs['iPodderXSerialNumber']
- if len(regCode) > 5:
- return 1
- else:
- return 0
- except:
- return 0
-
-
-
- def getHistory():
- print 'Loading History...'
- sys.stdout.flush()
- if os.path.isfile(historyFile):
-
- try:
- tempHist = plistlib.Plist.fromFile(file(historyFile))
- tempHist = plistlib.Plist()
- tempHist['downloadHistory'] = list('')
- tempHist.write(historyFile)
-
- else:
- tempHist = plistlib.Plist()
- tempHist['downloadHistory'] = list('')
- tempHist.write(historyFile)
-
- try:
- items = []
- guids = []
- for historyItem in tempHist['downloadHistory']:
-
- try:
- items.append(historyItem['enclosureURL'])
- guids.append(historyItem['encGUID'])
- continue
- continue
-
- except:
- items = list('MakeSureHistoryArrayIsNotEmpty')
-
- return (tempHist, items, guids)
-
-
- def saveHistory(url, feedURL, encGUID, saveName, time, feedTitle, feedLink, saveDir, pubDate, itemTitle, fileID, status, description, location):
- if DEBUG:
- print 'Saving History...'
-
- histDict = {
- 'feedTitle': feedTitle,
- 'feedURL': feedURL,
- 'enclosureURL': url,
- 'encGUID': encGUID,
- 'file': saveName,
- 'downloadTime': time,
- 'path': saveDir,
- 'pubDate': pubDate,
- 'entryTitle': itemTitle,
- 'importedID': fileID,
- 'status': bool(status),
- 'description': description,
- 'import': location,
- 'status': status }
- History['downloadHistory'].append(histDict)
- History.write(historyFile)
- historyURLs.append(url)
- encGUIDs.append(encGUID)
- anonFeedback = 1
-
- try:
- anonFeedback = int(Prefs['anonFeedback'])
- except:
- pass
-
- if anonFeedback and status > 0:
- pingURL = 'http://directory.iPodderX.com/feedData/survey/files?url=' + url + '&feed=' + feedURL
- if DEBUG:
- print 'Pinging survey server: ' + pingURL
-
-
- try:
- handle = urllib.urlopen(pingURL)
-
-
- if DEBUG:
- print 'Done saving History...'
-
-
-
- def dummychoose(default, size, saveas, dir):
- globals()['totalBTFileSize'] = float(size) / (1 << 20)
- return saveas
-
-
- def dummydisplay(dict):
-
- try:
- print ';;%.2f;;%.2f' % (totalBTFileSize, dict['downTotal'])
- sys.stdout.flush()
- except Exception:
- inst = None
-
-
-
- def dummyerror(message):
- logIt(message)
-
-
- def getTorrent(torrent, maxUploadRate, saveLocation, saveName):
- logIt('Downloading Torrent: ' + torrent)
- print 'Downloading ' + saveName
- sys.stdout.flush()
-
- try:
- checkDir(saveLocation)
- ev = Event()
-
- def fin(ev = ev):
- ev.set()
-
- params = [
- '--url',
- torrent,
- '--max_upload_rate',
- maxUploadRate,
- '--saveas',
- saveLocation + '/' + saveName]
- download.download(params, dummychoose, dummydisplay, fin, dummyerror, ev, 80)
- logIt('Completed Download: %s' % saveName)
- except Exception:
- msg = None
- logIt('Torrent Download Failed')
- logIt('ERRORMSG: ' + str(msg))
-
-
-
- def displayProgress(block_count, block_size, total_size):
- print ';;%.2f;;%.2f' % (float(total_size) / 1024, float(block_count * block_size) / 1024)
- sys.stdout.flush()
-
-
- def getFile(url, saveLocation, saveName):
- status = 1
- logIt('Downloading File: ' + url)
- print 'Downloading ' + saveName
- sys.stdout.flush()
- checkDir(saveLocation)
-
- try:
- headers = urllib.urlretrieve(url, saveLocation + '/' + saveName, displayProgress)
- logIt('Completed Download: %s' % saveName)
- status = 1
- except Exception:
- msg = None
- logIt('Download Failed')
- logIt(str(msg))
- status = 0
- return status
-
-
-
- def getRSS(feed, etagInfo):
- etagInfoNew = ''
-
- try:
- if len(etagInfo) > 1:
- parsedFeed = feedparser.parse(feed, etag = etagInfo, agent = USER_AGENT)
-
- try:
- etagInfoNew = parsedFeed.etag
-
- else:
- parsedFeed = feedparser.parse(feed, agent = USER_AGENT)
-
- try:
- etagInfoNew = parsedFeed.etag
- except:
- pass
-
- if parsedFeed.status == 304:
- logIt('No new content found...')
- except Exception:
- inst = None
- logIt('getRSS ERRMSG: ' + str(inst))
- logIt('feedparser ERRMSG: ' + str(parsedFeed.debug_message))
- logIt('Bozo Exceptoin: ' + parsedFeed['bozo_exception'])
-
- return (str(etagInfoNew), parsedFeed)
-
-
- def prepURL(url):
- if url[:8] != 'https://':
- if url[:7] != 'http://':
- url = 'http://' + url
-
-
- return url
-
-
- def url2file(url):
- url = url.replace('http://', '')
- url = url.replace('/', '.')
- return url
-
-
- def feedIdHash(feedURL):
- import md5
- item = md5.new
- item.create(feedURL)
- return item.hexdigest
-
-
- def parseURL(url):
- url = url.replace('http://', '')
- split = url.split('/')
- server = split[0]
- rssFile = '/' + '/'.join(split[1:len(split)])
- return (server, rssFile)
-
-
- def checkDir(dir):
- if not os.path.isdir(dir):
- os.mkdir(dir)
-
-
-
- def checkForOtherInstances():
- if int(os.popen('ps auxww | grep -i iPodderX.py | grep -v /bin/sh | grep -w -v ps | wc -l', 'r').readline().strip()) > 2:
- logIt('iPodderX is already scanning your feeds with Auto Check')
- print 'iPodderX is already scanning your feeds with Auto Check'
- sys.exit()
-
-
-
- def detectFileType(fileName):
- logIt('Detecting file type...')
-
- try:
- type = typeFile.file(fileName)
- except Exception:
- msg = None
- logIt('Failed to detect type, using data')
- logIt(msg)
- type = data
-
- if re.search('ascii', type, re.IGNORECASE):
- f = open(fileName, 'r')
- for line in f.readlines():
- if re.search('<html>', line, re.IGNORECASE):
- type = 'html'
- break
- continue
-
-
- if re.search('xml', type, re.IGNORECASE):
- f = open(fileName, 'r')
- for line in f.readlines():
- if re.search('<rss', line, re.IGNORECASE):
- type = 'rss'
- break
- continue
- if re.search('<opml', line, re.IGNORECASE):
- type = 'opml'
- break
- continue
-
-
- logIt('File type is ' + type)
- return type
-
-
- def downloadFile(url, saveDir, saveName, folderName, customGenre):
- fileID = 0
- location = ''
- status = 1
- url = prepURL(url)
- if re.search('torrent$', url, re.IGNORECASE):
- saveName = saveName[0:len(saveName) - 8]
- getTorrent(url, 0, saveDir, saveName)
- type = detectFileType(saveDir + '/' + saveName)
- if re.search('audio', type, re.IGNORECASE):
- (fileID, location) = updatePlaylist(saveDir, saveName, folderName, customGenre)
- elif re.search('image', type, re.IGNORECASE):
- (fileID, location) = updateiPhoto(saveDir, saveName, folderName)
-
- return (saveName, fileID, location)
- else:
- status = getFile(url, saveDir, saveName)
- if not (status == 0):
- status = 1
- type = detectFileType(saveDir + '/' + saveName)
- if re.search('torrent', type, re.IGNORECASE):
- os.unlink(saveDir + saveName)
- if torrentFiles > 0:
- if re.search('.torrent$', type, re.IGNORECASE):
- saveName = saveName[0:len(saveName) - 8]
-
- getTorrent(url, 0, saveDir, saveName)
- type = typeFile.file(saveDir + '/' + saveName)
- if re.search('audio', type, re.IGNORECASE):
- (fileID, location) = updatePlaylist(saveDir, saveName, folderName, customGenre)
- elif re.search('image', type, re.IGNORECASE):
- (fileID, location) = updateiPhoto(saveDir, saveName, folderName)
-
-
- elif re.search('audio', type, re.IGNORECASE):
- if moveAudio > 0:
- (fileID, location) = updatePlaylist(saveDir, saveName, folderName, customGenre)
-
- elif re.search('image', type, re.IGNORECASE):
- if moveImages > 0:
- (fileID, location) = updateiPhoto(saveDir, saveName, folderName)
-
- elif re.search('html', type, re.IGNORECASE):
- os.unlink(saveDir + saveName)
- return None
-
- return (saveName, fileID, location)
- else:
- os.unlink(saveDir + saveName)
- return status
-
- if __name__ == '__main__':
- downloadCount = 0
- for arg in sys.argv:
- if arg == '-debug':
- DEBUG = 1
- continue
-
- if DEBUG:
- print '--- DEBUG ENABLED ---'
-
- if checkReg() == 0:
- print USER_AGENT + ' is UNREGISTERED, Please register today!'
- sys.exit(0)
-
- checkForOtherInstances()
- trimLog()
- logIt('\r\n' + 'iPodderX (' + VERSION + ') Feed Scan Started: ' + strftime('%H:%M:%S -- %m/%d/%Y', localtime()))
- downloadDirectory = downloadDir()
-
- try:
- onlyAudio = int(Prefs['onlyAudio'])
- except:
- onlyAudio = 0
-
-
- try:
- moveAudio = int(Prefs['moveAudio'])
- except:
- moveAudio = 1
-
-
- try:
- moveImages = int(Prefs['moveImages'])
- except:
- moveImages = 1
-
-
- try:
- deleteAudio = int(Prefs['deleteAudio'])
- except:
- deleteAudio = 0
-
-
- try:
- deleteImages = int(Prefs['deleteImages'])
- except:
- deleteImages = 0
-
-
- try:
- torrentFiles = int(Prefs['torrentFiles'])
- except:
- torrentFiles = 1
-
-
- try:
- organizeDownloads = int(Prefs['organizeDownloads'])
- except:
- organizeDownloads = 0
-
- initialize()
- (History, historyURLs, encGUIDs) = getHistory()
- feedDetails = FeedListPrefs['iPodderXFeeds']
- if len(historyURLs) == 0:
- historyURLs = [
- 'MakeSureHistoryArrayIsNotEmpty']
-
- if len(encGUIDs) == 0:
- encGUIDs = [
- 'MakeSureGUIDArrayIsNotEmpty']
-
- for feed in feedDetails:
- counter = 10000000
- podcasts = { }
-
- try:
- enabled = feed['enabled']
- except:
- enabled = 1
-
-
- try:
- downloadBehavior = int(feed['downloadBehavior'])
- except:
- downloadBehavior = 0
-
-
- try:
- customFolder = feed['customFolder']
- except:
- customFolder = ''
-
-
- try:
- customGenre = feed['customGenre']
- except:
- customGenre = ''
-
-
- try:
- if enabled:
- print 'Checking ' + feed['feedTitle'] + '...'
- sys.stdout.flush()
- except:
- pass
-
- if enabled:
- feedURL = prepURL(feed['feedURL'])
- logIt('Checking ' + feedURL + '...')
- parsedFeed = { }
-
- try:
- if DEBUG:
- (etag, parsedFeed) = getRSS(feedURL, '')
- else:
-
- try:
- (etag, parsedFeed) = getRSS(feedURL, feed['etag'])
- except:
- (etag, parsedFeed) = getRSS(feedURL, '')
-
- except Exception:
- inst = None
- logIt('Error parsing feed. RSS may be poorly formatted...')
- logIt('ERRMSG: ' + str(inst))
-
-
- try:
-
- try:
- itemList = parsedFeed.entries
- except Exception:
- inst = None
- logIt('Error getting items')
- logIt('ERRMSG: ' + str(inst))
-
- if len(itemList) > 0:
-
- try:
- feedTitle = latin1_to_ascii(parsedFeed.feed.title)
- except:
- pass
-
-
- try:
- itemDescription = latin1_to_ascii(item['description'])
- except:
- itemDescription = 'No description'
-
-
- try:
- feedLink = parsedFeed.feed.link
- except:
- feedLink = feedURL
-
- feed['lastChecked'] = strftime('%a, %d %b %Y %H:%M:%S %Z', localtime())
- feed['etag'] = etag
- feed['feedTitle'] = feedTitle
- feed['siteURL'] = feedLink
- feed['downloadBehavior'] = '0'
-
- if len(itemList) > 0:
- for item in itemList:
-
- try:
- if item['modified_parsed'] == None:
- pubDate = gmtime()
- else:
- pubDate = item['modified_parsed']
- except:
- pubDate = gmtime()
-
-
- try:
- itemTitle = latin1_to_ascii(item['title'])
- except:
- itemTitle = 'No title'
-
-
- try:
- itemDescription = latin1_to_ascii(item['description'])
- except:
- itemDescription = 'No description'
-
- if len(customFolder) > 0:
- sortDir = customFolder
- elif organizeDownloads == 1:
- sortDir = strftime('%Y-%m-%d', pubDate)
- else:
- sortDir = feedTitle.replace('/', '-')
- if sortDir[0] == '.':
- sortDir = 'dot' + sortDir[1:]
-
- saveDir = downloadDirectory + sortDir
-
- try:
- keywordsRaw = feed['keywords']
- keywords = keywordsRaw.split(',')
- except:
- keywords = []
-
-
- try:
- url = latin1_to_ascii(item.enclosures[0].url)
- except:
- url = ''
-
-
- try:
- length = item.enclosures[0].length
- except:
- length = ''
-
-
- try:
- type = item.enclosures[0].type
- except:
- type = ''
-
-
- try:
- encGUID = item.guid
- except:
- encGUID = latin1_to_ascii(item.enclosures[0].url)
-
- if len(keywords) > 0:
- for keyword in keywords:
- keywordSplit = keyword.split(' ')
- for word in keywordSplit:
- if re.search(word, url, re.IGNORECASE) and re.search(word, itemTitle, re.IGNORECASE) or re.search(word, itemDescription, re.IGNORECASE):
- didFind = 1
- counter -= 1
- continue
- didFind = 0
-
-
- else:
- didFind = 1
- okDownload = 0
- if didFind:
- if len(url) > 0 and didFind > 0:
- if encGUID in encGUIDs:
- okDownload = 0
- elif url in historyURLs:
- okDownload = 0
- else:
- okDownload = 1
-
- else:
- okDownload = 0
- if okDownload:
- saveNameSplit = url.split('/')
- saveName = saveNameSplit[len(saveNameSplit) - 1]
- saveName = latin1_to_ascii(saveName)
- if re.search('php$', saveName, re.IGNORECASE) or re.search('asp$', saveName, re.IGNORECASE):
- if re.search('audio', type, re.IGNORECASE):
- saveName = saveName[:-4] + '.mp3'
-
- if re.search('image', type, re.IGNORECASE):
- saveName = saveName[:-4] + '.jpg'
-
- if re.search('movie', type, re.IGNORECASE):
- saveName = saveName[:-4] + '.mpeg'
-
-
-
- try:
- modTime = mktime(item['modified_parsed'])
- podcasts['saveName' + '-' + str(modTime)] = (url, feedURL, encGUID, saveName, strftime('%a, %d %b %Y %H:%M:%S %Z', gmtime()), feedTitle, feedLink, saveDir, strftime('%a, %d %b %Y %H:%M:%S %Z', pubDate), itemTitle, itemDescription)
- podcasts['saveName' + '-' + str(counter)] = (url, feedURL, encGUID, saveName, strftime('%a, %d %b %Y %H:%M:%S %Z', gmtime()), feedTitle, feedLink, saveDir, strftime('%a, %d %b %Y %H:%M:%S %Z', pubDate), itemTitle, itemDescription)
-
- continue
-
- except Exception:
- inst = None
- logIt('Exception Caught: ' + str(inst))
- except:
- None<EXCEPTION MATCH>Exception
-
-
- None<EXCEPTION MATCH>Exception
- totalDownloads = 0
-
- try:
- keys = podcasts.keys()
- keys.sort()
-
- try:
- if keys[0] < keys[1]:
- keys.reverse()
- except:
- pass
-
- for key in keys:
- url = podcasts[key][0]
- feedURL = podcasts[key][1]
- encGUID = podcasts[key][2]
- saveName = podcasts[key][3]
- gmTime = podcasts[key][4]
- feedTitle = podcasts[key][5]
- feedLink = podcasts[key][6]
- saveDir = podcasts[key][7]
- pubDate = podcasts[key][8]
- itemTitle = podcasts[key][9]
- itemDescription = podcasts[key][10]
- saveHist = 1
- if downloadBehavior == 2 and totalDownloads < 3:
-
- try:
- (saveName, fileID, location) = downloadFile(url, saveDir, saveName, sortDir, customGenre)
- totalDownloads = totalDownloads + 1
- downloadCount = downloadCount + 1
- except Exception:
- inst = None
- logIt('ERRMSG: ' + str(inst))
- totalDownloads = totalDownloads + 1
- saveHist = 0
-
- if saveHist:
- saveHistory(url, feedURL, encGUID, saveName, gmTime, feedTitle, feedLink, saveDir, pubDate, itemTitle, fileID, 1, itemDescription, location)
-
- saveHist
- if downloadBehavior == 2 and totalDownloads > 2:
- saveHistory(url, feedURL, encGUID, saveName, gmTime, feedTitle, feedLink, saveDir, pubDate, itemTitle, 0, 0, '', '')
- continue
- if downloadBehavior == 1 and totalDownloads < 1:
-
- try:
- (saveName, fileID, location) = downloadFile(url, saveDir, saveName, sortDir, customGenre)
- totalDownloads = totalDownloads + 1
- downloadCount = downloadCount + 1
- except Exception:
- inst = None
- logIt('ERRMSG: ' + str(inst))
- totalDownloads = totalDownloads + 1
- saveHist = 0
-
- if saveHist:
- saveHistory(url, feedURL, encGUID, saveName, gmTime, feedTitle, feedLink, saveDir, pubDate, itemTitle, fileID, 1, itemDescription, location)
-
- saveHist
- if downloadBehavior == 1 and totalDownloads > 0:
- saveHistory(url, feedURL, encGUID, saveName, gmTime, feedTitle, feedLink, saveDir, pubDate, itemTitle, 0, 0, '', '')
- continue
- if downloadBehavior == 0:
-
- try:
- (saveName, fileID, location) = downloadFile(url, saveDir, saveName, sortDir, customGenre)
- totalDownloads = totalDownloads + 1
- downloadCount = downloadCount + 1
- except Exception:
- inst = None
- logIt('ERRMSG: ' + str(inst))
- totalDownloads = totalDownloads + 1
- saveHist = 0
-
- if saveHist:
- saveHistory(url, feedURL, encGUID, saveName, gmTime, feedTitle, feedLink, saveDir, pubDate, itemTitle, fileID, 1, itemDescription, location)
-
- saveHist
- continue
- except Exception:
- inst = None
- logIt('ERRMSG: ' + str(inst))
- continue
-
-
-
- FeedListPrefs = plistlib.Plist.fromFile(file(feedFile))
- feedDetailsNew = FeedListPrefs['iPodderXFeeds']
- for feedNew in feedDetailsNew:
- for feedOld in feedDetails:
-
- try:
- if feedNew['feedURL'] == feedOld['feedURL'] and feedOld['enabled'] > 0:
- feedNew['etag'] = 'Temp Value'
- feedNew.update(feedOld)
- if DEBUG:
- print 'Preferences for % has been updated' % feedNew['feedTitle']
-
- continue
- continue
-
-
-
- FeedListPrefs['iPodderXFeeds'] = feedDetailsNew
- FeedListPrefs.write(feedFile)
- if downloadCount > 0:
- print 'Successfully downloaded %d podcasts' % downloadCount
- logIt('Successfully downloaded ' + str(downloadCount) + ' podcasts')
-
- logIt('iPodderX Feed Scan Complete: ' + strftime('%H:%M:%S -- %m/%d/%Y', localtime()))
-
-